
CMAKE_MINIMUM_REQUIRED(VERSION 3.7.2)

ADD_CUSTOM_TARGET(CTest
        COMMAND ctest
        DEPENDS ${COMPILER_EXECUTE_NAME} corelib
        COMMENT Run CTest ...
        )

SET(TEST_BIN_EXEC ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${COMPILER_EXECUTE_NAME})
SET(TEST_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/__test_tmp")
FILE(MAKE_DIRECTORY ${TEST_WORKING_DIRECTORY})
SET(TEST_TIMEOUT 10)

IF("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
    SET(EXE_FILE_PREFIX "")
    SET(EXE_FILE_SUFFIX ".exe")
ENDIF()

ADD_TEST(
        NAME test_usage
        COMMAND ${TEST_BIN_EXEC}
        WORKING_DIRECTORY ${TEST_WORKING_DIRECTORY}
)
SET_TESTS_PROPERTIES(test_usage PROPERTIES
        PASS_REGULAR_EXPRESSION "编译器命令行使用方式"
        FAIL_REGULAR_EXPRESSION "[^a-z]Error;ERROR;Failed"
        TIMEOUT ${TEST_TIMEOUT}
        )

ADD_TEST(
        NAME test_array1
        COMMAND ${TEST_BIN_EXEC} --project array1 ${TESTSUIT_SOURCES_DIRECTORY}array1.txt -o ${EXE_FILE_PREFIX}array1${EXE_FILE_SUFFIX}
        WORKING_DIRECTORY ${TEST_WORKING_DIRECTORY}
)
SET_TESTS_PROPERTIES(test_array1 PROPERTIES
        PASS_REGULAR_EXPRESSION "测试输出字符串"
        PASS_REGULAR_EXPRESSION "这是另一个字符串"
        FAIL_REGULAR_EXPRESSION "[^a-z]Error;ERROR;Failed"
        TIMEOUT ${TEST_TIMEOUT}
        )

ADD_TEST(
        NAME test_gcd_algorithm
        COMMAND ${TEST_BIN_EXEC} --project gcd_algorithm ${TESTSUIT_SOURCES_DIRECTORY}gcd_algorithm.txt -o ${EXE_FILE_PREFIX}gcd_algorithm${EXE_FILE_SUFFIX}
        WORKING_DIRECTORY ${TEST_WORKING_DIRECTORY}
)
SET_TESTS_PROPERTIES(test_gcd_algorithm PROPERTIES
        PASS_REGULAR_EXPRESSION "6"
        FAIL_REGULAR_EXPRESSION "[^a-z]Error;ERROR;Failed"
        TIMEOUT ${TEST_TIMEOUT}
        )

ADD_TEST(
        NAME test_ref_param
        COMMAND ${TEST_BIN_EXEC} --project ref_param ${TESTSUIT_SOURCES_DIRECTORY}ref_param.txt -o ${EXE_FILE_PREFIX}ref_param${EXE_FILE_SUFFIX}
)
SET_TESTS_PROPERTIES(test_gcd_algorithm PROPERTIES
        PASS_REGULAR_EXPRESSION "0;10"
        FAIL_REGULAR_EXPRESSION "[^a-z]Error;ERROR;Failed"
        TIMEOUT ${TEST_TIMEOUT}
        )

INSTALL(FILES
        array1.txt
        gcd_algorithm.txt
        ref_param.txt
        DESTINATION share/rex/example
        )
